package com.accounting.client.frontend.order;

import java.util.ArrayList;
import java.util.List;

import com.accounting.client.remote.obj.OrderItem;

import corelib.client.delegate.Func1;
import corelib.client.linq.Linq;
import corelib.client.ui.widget.layout.RelativeColumn;

public class OrderItemsPanel extends RelativeColumn {
	
	private final List<OrderItemRow> orderItemIndex = new ArrayList<OrderItemRow>();
	
	public OrderItemRow addOrderRow(OrderItemRow row) {
		this.orderItemIndex.add(row);
		return (OrderItemRow) super.addRow(row);
	}
	
	public void removeOrderRow(OrderItemRow row){
		removeRow(row);
		this.orderItemIndex.remove(row);
	}
	
	public List<OrderItem> getOrderItem(){
		return Linq.select(orderItemIndex, new Func1<OrderItemRow, OrderItem>() {
				@Override
				public OrderItem run(OrderItemRow param) {
					return param.getData();
				}
		});
	}
	
	@Override
	public void clear(){
		super.clear();
		this.orderItemIndex.clear();
	}

	public List<OrderItemRow> getOrderItemIndex() {
		return this.orderItemIndex;
	}
	
}
